using System.Drawing;
using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.BO;
using Habanero.Faces.Base;
using Habanero.Faces.Win;

namespace FireStarterModeller.UI
{
    /// <summary>
    /// The <see cref="IBOSelectorAndEditor"/> for editing the <see cref="DMProperty"/>s of the <see cref="DMClass"/>.
    /// This control also contains the <see cref="DMUniqueConstraintPropertySelectorControl"/> for managing
    ///  the <see cref="DMProperty"/>'s that make up the unique constraint.
    /// </summary>
    public class DMUniqueConstraintAndPropertyEditorControl : PanelWin //, IFormControl
    {
        private DMClass _dmClass;
        public IBOParentChildrenSelector UniqueConstraintEditorControl { get; private set; }

        public DMUniqueConstraintAndPropertyEditorControl(IControlFactory controlFactory)
        {
            UniqueConstraintEditorControl = new DMUniqueConstraintColEditorControl(controlFactory);
            IControlHabanero control = UniqueConstraintEditorControl;
            IGroupBox uniqueConstraintGroupBox = controlFactory.CreateGroupBox();
            uniqueConstraintGroupBox.Controls.Add(control);
            control.Top = 10;
            control.Left = 5;
            uniqueConstraintGroupBox.Height = UniqueConstraintEditorControl.MinimumSize.Height + 20;
            uniqueConstraintGroupBox.MinimumSize = new Size
                (UniqueConstraintEditorControl.MinimumSize.Width + 10, uniqueConstraintGroupBox.Height);

            BorderLayoutManager layoutManager = controlFactory.CreateBorderLayoutManager(this);
            layoutManager.AddControl(uniqueConstraintGroupBox, BorderLayoutManager.Position.North);

            this.Enabled = false;
            this.Height = uniqueConstraintGroupBox.MinimumSize.Height;
            this.MinimumSize = new Size(uniqueConstraintGroupBox.MinimumSize.Width, this.Height);
        }

        /// <summary>
        /// The <see cref="DMClass"/> whose <see cref="DMProperty"/>s are being edited by this control
        /// </summary>
        public DMClass Class
        {
            get { return _dmClass; }
            set
            {
                _dmClass = value;
                this.UniqueConstraintEditorControl.BusinessObject = _dmClass;
                UpdateState();
            }
        }

        private void UpdateState()
        {
            this.Enabled = _dmClass != null;
        }


        /// <summary>
        /// The <see cref="IBusinessObjectCollection"/> of <see cref="DMUniqueConstraint"/>s  being managed by this control.
        /// </summary>
        public BusinessObjectCollection<DMUniqueConstraint> UniqueConstraints
        {
            get
            {
                return
                    (BusinessObjectCollection<DMUniqueConstraint>)
                    UniqueConstraintEditorControl.BusinessObjectCollection;
            } //        }
        }

        /// <summary>
        /// The <see cref="DMUniqueConstraint"/> currently selected in the Grid (i.e. currently being edited)
        /// </summary>
        public DMUniqueConstraint DMUniqueConstraint
        {
            get { return (DMUniqueConstraint) UniqueConstraintEditorControl.SelectedBusinessObject; }
            set { UniqueConstraintEditorControl.SelectedBusinessObject = value; }
        }

 //       /// <summary>
   //     /// The <see cref="DMUniqueConstraintPropertySelectorControl"/> that is being used to manage the <see cref="DMPropRule"/>s for the currently selected 
     //   ///   <see cref="DMProperty"/>
       // /// </summary>
        //public DMUniqueConstraintPropertySelectorControl DMUniqueConstraintPropertySelectorControl
        //{
        //    get { return _dmDMUniqueConstraintPropControl; }
        //}


//        public void SetForm(IFormHabanero form)
//        {
//        }
    }
}